#!/usr/bin/env node

const mysql = require('mysql2/promise'),
      log   = console.log;

let con = mysql.createPool({
  host:'127.0.0.1',
  user:'root',
  password:'ddd',
  database:'test'
})

getAreas();

async function getAreas(areaname){
  const sql = `insert into areas(area_name) values('${areaname}')`;

  let [rows] = await con.execute(sql);

  return rows
  //exectue sql
};

async function getAreas(areaname){
  const sql ='select * from areas';

  let [rows] = await con.execute(sql);

  return rows
  //exectue sql
};

async function updateAreas(oldname,newname){
  const sql =`update areas set area_name = '${newname}' where area_name = '${oldname}'`;

  let [rows] = await con.execute(sql);

  return rows
  //exectue sql
};

async function delAreas(areaname){
  const sql =`delete from areas where area_name = '${areaname}'`;

  let [rows] = await con.execute(sql);

  return rows
  //exectue sql
};

(async function() {
  //await addAreaa('英国');
  //await updateAreas('大陆','内地');
  await delAreas('大陆');
  log(await getAreas());
})();
